package com.example.wechat114.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.wechat114.commons.JsonBean;
import com.example.wechat114.entity.GForm;
import com.example.wechat114.entity.MForm;
import com.example.wechat114.entity.Registered;
import com.example.wechat114.mapper.GFormMapper;
import com.example.wechat114.service.GFormService;
import com.example.wechat114.service.MFormService;
import com.example.wechat114.service.RegisteredService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 张超杰
 * @company 张超杰
 * @create 2021-11-25 15:45
 */
@RestController
@RequestMapping("registered")
public class RegisteredController {
    @Autowired
    private RegisteredService registeredService;

    @Autowired
    private GFormService gFormService;

    @Autowired
    private MFormService mFormService;

    @RequestMapping("addRegistered")
    public JsonBean addRegistered(Registered registered,String mid,String status1){
        JsonBean jsonBean = new JsonBean(-1,"添加失败",null);
        GForm gForm = new GForm();
        gForm.setDay(registered.getDatetime());
        gForm.setMid(Integer.valueOf(mid));
        JsonBean jsonBean2 = gFormService.selectOne(gForm);
        GForm gForm1 = (GForm) jsonBean2.getData();
        JsonBean jsonBean1 = gFormService.updateGform(gForm1,status1);
        if(jsonBean1.getCode()==0) {
            jsonBean = registeredService.addRegisteredService(registered);
        }

        return jsonBean;
    }

    @PostMapping("getRegistered")
    public JsonBean getRegistered(String phon){
        return registeredService.getRegistered(phon);
    }

    @PostMapping("getRegisteredByid")
    public JsonBean getRegisteredByid(Integer id){
        return registeredService.getRegisteredByid(id);
    }
}
